package com.bwie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bwie.mapper.TbCourseMapper;
import com.bwie.mapper.TbDifficultyMapper;
import com.bwie.pojo.TbCourse;
import com.bwie.service.TbCourseService;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * description:
 *
 * @Author caoshuaifeng
 * @Create 2025/3/12 10:42
 * @Version 1.0
 */
@Service
public class TbCourseServiceImpl implements TbCourseService {

    @Autowired
    TbCourseMapper tbCourseMapper;

    @Autowired
    TbDifficultyMapper tbDifficultyMapper;
    @Override
    public R getCourseList(PageInfoVo pageInfoVo) {
        Page<TbCourse> page = new Page<>(pageInfoVo.getPageNum(), pageInfoVo.getPageSize());
        QueryWrapper<TbCourse> wrapper = new QueryWrapper<>();
        if(pageInfoVo.getKeyWord()!=null){
            wrapper.like("course_name",pageInfoVo.getKeyWord());
        }
        if(pageInfoVo.getTypeId()!=null){
            wrapper.lambda().eq(TbCourse::getDifficultyId,pageInfoVo.getTypeId());
        }

        tbCourseMapper.selectPage(page, wrapper);
        return R.OK(page);
    }

    @Override
    public R getDifficulty() {
        return R.OK(tbDifficultyMapper.selectList(null));
    }

    @Override
    public R getCourseById(TbCourse tbCourse) {
        TbCourse userId = tbCourseMapper.selectById(tbCourse.getUserId());
        return R.OK(userId);

    }

}
